package com.vj.space.api.modules.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vj.space.api.modules.entity.User;
import com.vj.space.api.modules.mapper.UserMapper;
import com.vj.space.api.modules.service.UserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public Map<String, Object> login(User user) {
        Map<String, Object> result = new HashMap();
        result.put("result", false);
        LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery();
        if(StrUtil.isNotBlank(user.getUserName())) {
            wrapper.eq(User::getUserName, user.getUserName());
        }
        if(StrUtil.isNotBlank(user.getUserBindPhone())){
            wrapper.eq(User::getUserBindPhone, user.getUserBindPhone());
        }
        wrapper.eq(User::getUserPass, user.getUserPass());
        User one = this.getOne(wrapper);
        if(one != null) {
            result.put("result", true);
            result.put("info", one);
        }
        return result;
    }
}
